#include <iostream>
#include "contacts.pb.h"

int main()
{
    contacts::PeopleInfo peopleInfo;
    peopleInfo.set_id(1);
    peopleInfo.set_name("Texas");
    peopleInfo.set_age(19);
    std::string peopleInfoString = peopleInfo.SerializeAsString(); //序列化为二进制字符串

    contacts::PeopleInfo student;
    if(student.ParseFromString(peopleInfoString)) //反序列化为PeopleInfo对象
    {
        std::cout 
            << "student[id = " << std::to_string(student.id()) 
            << ", name = " << student.name() 
            << ", age = " << std::to_string(student.age())
            << "]" 
            << std::endl;
    }
    else
    {
        std::cout << "反序列化失败" << std::endl;
        return -1;
    }

    return 0;
}